package com.nf.health.app.activity.doctor_advice.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.nf.health.app.R;
import com.nf.health.app.activity.doctor_advice.bean.AdviceDetail;

import java.util.List;

/**
 * 用药处方adapter
 */

public class MedicinePrescriptionAdapter extends BaseAdapter {
    private Context context;
    private List<AdviceDetail.MedicationBean>   datas;
    public MedicinePrescriptionAdapter(Context context,  List<AdviceDetail.MedicationBean> datas) {
        this.context = context;
        this.datas = datas;
    }
    public void   setAdapterDataChanged(List<AdviceDetail.MedicationBean> datas) {
        this.datas = datas;
        notifyDataSetChanged();
    }
    public void setSubDataChanged(List<AdviceDetail.MedicationBean> datas) {
        this.datas = datas;
        notifyDataSetChanged();
    }
    @Override
    public int getCount() {
        if(datas!=null&&datas.size()>0){
            return datas.size();
        }
        return 0;
    }

    @Override
    public Object getItem(int arg0) {
        return datas.get(arg0);
    }

    @Override
    public long getItemId(int arg0) {
        return arg0;
    }

    @Override
    public View getView(final int position, View convertview, ViewGroup arg2) {
        ViewHolder holder = null;
        AdviceDetail.MedicationBean medicationBean = datas.get(position);
        if (convertview == null) {
            convertview = View.inflate(context, R.layout.teim_medicineprescriptiona, null);
            holder = new ViewHolder();
            holder.tv_per_medicine_prescription = (TextView) convertview.findViewById(R.id.tv_per_medicine_prescription);
            convertview.setTag(holder);
        } else {
            holder = (ViewHolder) convertview.getTag();
        }
        String everyDayNum = TextUtils.isEmpty(medicationBean.getEveryDayNum()) ? "" : medicationBean.getEveryDayNum();
        String medicineMethod = TextUtils.isEmpty(medicationBean.getMedicineMethod()) ? "" : medicationBean.getMedicineMethod();// "外用",
        String medicineName = TextUtils.isEmpty(medicationBean.getMedicineName()) ? "" : medicationBean.getMedicineName();//155555",
        String medicineTime = TextUtils.isEmpty(medicationBean.getMedicineTime()) ? "" : medicationBean.getMedicineTime();
        String onceNum = TextUtils.isEmpty(medicationBean.getOnceNum()) ? "" : medicationBean.getOnceNum();//
        String totalDay = TextUtils.isEmpty(medicationBean.getTotalDay()) ? "" : medicationBean.getTotalDay();
        String unit = TextUtils.isEmpty(medicationBean.getUnit()) ? "" : medicationBean.getUnit();//
        holder.tv_per_medicine_prescription.setText(
            ""+medicineName +"    "+
            ""+medicineMethod +"    "+
            "共计"+totalDay +"天    "+
            ""+everyDayNum +"次/日    "+
            ""+onceNum +unit+"/次    "+
            ""+medicineTime +""
        );
        return convertview;
    }
      class ViewHolder{
        TextView tv_per_medicine_prescription;
    }



}
